package com.firstgroup.dms.controller;

import com.firstgroup.dms.common.Result;
import com.firstgroup.dms.pojo.Employee;
import com.firstgroup.dms.service.EmployeeService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @GetMapping("/all")
    public List<Employee> getAllEmployees() {
        return employeeService.getAllEmployees();
    }

    @GetMapping("/{id}")
    public Result<Employee> getById(@PathVariable Integer id) {
        return employeeService.getById(id);
    }

    @PostMapping("/add")
    public Result<Object> add(@RequestBody Employee employee) {
        return employeeService.add(employee);
    }

    @PutMapping("/update")
    public Result<Object> update(@RequestBody Employee employee) {
        return employeeService.update(employee);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Integer id) {
        return employeeService.deleteById(id);
    }

    @GetMapping("/list")
    public Result<Map<String, Object>> getList(
            Employee condition,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit) {
        return employeeService.getList(condition, page, limit);
    }
}
